﻿using MengLin.OOP.DesignPattern.State.TrafficLights.Abstract;
using MengLin.OOP.DesignPattern.State.TrafficLights.Implements;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MengLin.OOP.DesignPattern.State.TrafficLights
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 传统写法
            {

            }
            #endregion

            #region 错误写法
            //{
            //    AbstractLight light = new GreenLight();
            //    light.Show();
            //    light.Turn();//变灯的颜色，绿灯就是绿灯，颜色怎么能改变
            //}
            #endregion

            #region 状态模式写法
            {
                AbstractLight light = new GreenLight();
                Context context = new Context()
                {
                    CurrentLight = light
                };
                //调用相同的行为，但是产生的动作是不同的
                //绿灯
                Console.WriteLine("==================================");
                context.Show();
                context.Change();
                //黄灯
                Console.WriteLine("==================================");
                context.Show();
                context.Change();
                //红灯
                Console.WriteLine("==================================");
                context.Show();
                context.Change();
            }
            #endregion
            Console.Read();
        }
    }
}
